package com.bigbee.sort;
/**
 * 冒泡排序
 * @author gyf
 *
 */
public class bubsort {
	
	int [] num = new int[10];
	
	/*{
		for(int n = 0 ;n < num.length ; n ++){
			num[n] = (int) (Math.random() * 10);
			System.out.println(num[n]);
		}
	}*/
	public int[] bubsort(int[] num){
		int tem ;
		for(int n = 0 ; n < num.length - 1 ; n ++){
			for(int m = 0;m < num.length - 1; m ++){
				if(num[m] > num[m+1]){
					tem = num[m+1];
					num[m+1] = num[m];
					num[m] = tem;
				}
			}
		}
		return num;
	}
	public int[] bubsort2(int[] arr){
		for(int i=0;i<arr.length;i++)
		   {
			   for(int j=0;j<arr.length-1-i;j++)
			   {
				   if(arr[j]>arr[j+1])
				   {
					   int temp;
					   temp=arr[j];
					   arr[j]=arr[j+1];
					   arr[j+1]=temp;
				   }
			   	}
		   }
		return arr;
	}
	
	public static void main(String[] args) {
		int[] num = new int[10];
		String s = "" ;
		for(int n = 0 ;n < num.length ; n ++){
			num[n] = (int) (Math.random() * 10);
			s += num[n] + ",";
		}
		System.out.println(num.toString());
		System.out.println(s.substring(0, s.length() - 1));
		s = "";
		bubsort bub = new bubsort();
		int[] num2 = bub.bubsort(num);
		for(int n : num2){
			s += n + ",";
		}
		System.out.println(s.substring(0, s.length() - 1));
		s = "";
		int[] num3 = bub.bubsort2(num);
		for(int n : num3){
			s += n + ",";
		}
		System.out.println(s.substring(0, s.length() - 1));
	}
}
